package data;

import org.jboss.netty.buffer.ChannelBuffer;

import rank.PVPRankNode;
import util.ChannelBufferUtil;

public class RankPlayer implements ISerializable, Comparable<RankPlayer> {
	public String name;
	public String guid;
	public int sex;
	public int level;	
	
	public int pvpRank = -1;
	public int pvpScore;
	public int pvpLevel;
	public int pvpWinPercent;
	public int pvpCount;
	public int pvpWinCount;
	
	//	public int trainRank = -1;
//	public int trainLevel = 0;
	
	public int lastRefreshDay = -1;
	public int lastChallangeDay = -1;
	
	public int todayRefreshCount;
	public int todayChallangeCount;
	
//	public long lastEnterPVPTime = 0;
	
	public PVPRankNode pvpRankNode;
//	public TrainRankNode trainRankNode;
	
	public void changePVPCount(boolean win) {
		pvpCount++;
		if (win) { 
			pvpWinCount++;
		}
		updatePVPWinPercent();
	}
	
	public void updatePVPWinPercent() {
		pvpWinPercent = (int)((float)pvpWinCount*100/pvpCount);
	}
	
	
	@Override
	public int compareTo(RankPlayer other) {
		return other.pvpScore - this.pvpScore;
	}
	
	
//	public ChallengeRecord challengeRecord;
//	public void addRecord(RankPlayer enemy, boolean win, boolean positive) {
//		if (challengeRecord == null) {
//			challengeRecord = new ChallengeRecord();
//		}
//		challengeRecord.add(enemy, win, positive);
//	}
	
//	public void serializeChallengeRecord(ChannelBuffer buf) {
//		if (challengeRecord == null) {
//			buf.writeInt(0);
//		} else {
//			challengeRecord.serialize(buf);
//		}
//	}

	
	@Override
	public void serialize(ChannelBuffer buf) {
		ChannelBufferUtil.writeString(buf, guid);
		buf.writeByte(sex);
		ChannelBufferUtil.writeString(buf, name);
		buf.writeInt(level);
		buf.writeInt(pvpScore);
		buf.writeInt(pvpRank);
		buf.writeInt(pvpWinPercent);
	}
	
	@Override
	public void unserialize(ChannelBuffer buf) {

	}	
}
